﻿using GenericHtml;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using WLFramework.Json;
using WLFramework.Web;

namespace SampleSite.admin.ajax
{
    /// <summary>
    /// getUsers 的摘要说明
    /// </summary>
    public class getUsers : AjaxHttpHandler
    {
        public override void OnProcessRequest(HttpContext context)
        {
            int page = context.GetValueByName<int>("page");
            int rows = context.GetValueByName<int>("rows");
            string ucname = context.GetValueByName<string>("U_CName");

            if (ucname == null)
                ucname = "";

            using (var db = new PermissionContext())
            {
                var users = db.View_User.Where(k => k.U_State != 2 && k.U_CName.Contains(ucname));

                context.Response.Write(JSON.Instance.ToJSON(new
                {
                    total = users.Count(),
                    rows = users.Skip((page - 1) * rows).Take(rows)
                    .Select(k => new
                    {
                        U_ID = k.U_ID,
                        U_State = k.U_State == 0 ? "禁用" : "启用",
                        U_LoginNO = k.U_LoginNO,
                        U_CName = k.U_CName,
                        U_EName = k.U_EName,
                        U_IDCard = k.U_IDCard,
                        U_Sex = k.U_Sex == 1 ? "男" : "女",
                        U_BirthDay = ((DateTime)k.U_BirthDay).ToString("yyyy-MM-dd"),
                        U_HomeTel = k.U_HomeTel,
                        U_MobileNo = k.U_MobileNo,
                        U_Email = k.U_Email,
                        U_CompanyMail = k.U_CompanyMail
                    }).ToList()
                }));
            }
        }
    }
}